<title>客户资料</title>
<!--当前位置开始-->
<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <script type="text/html" template lay-done="layui.data.updateMainBreadcrumb();">
        </script>
    </div>
</div>
<!--当前位置结束-->
<style>
    /* 重写样式 */
</style>
<script type="text/html" template lay-type="Post" lay-url="{{ layui.setter.apiUrl }}Api/CoreCmsUser/GetIndex" lay-done="layui.data.done(d);">
</script>
<div class="table-body">
    <table id="LAY-app-CoreCmsUser-tableBox" lay-filter="LAY-app-CoreCmsUser-tableBox"></table>
</div>

<script type="text/html" id="LAY-app-CoreCmsUser-toolbar">
    <form class="layui-form coreshop-toolbar-search-form" id="LAY-app-CoreCmsUser-toolbar-form">
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-md12">
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="companyId" lay-filter="select-companyId-filter">
                                <option value="">请选择公司</option>
                                {{# layui.each(indexData.companyList, function(index, item){ }}
                                <option value="{{ item.id }}">{{ item.companyName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select id="departmentSelect" name="departmentId" lay-filter="select-departmentId-filter">
                                <<option value="">请选择部门</option>
                                <!--{{# layui.each(indexData.departmentList, function(index, item){ }}
                                <option value="{{ item.id }}">{{ item.depName }}</option>
                                {{# }); }}-->
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="groupId" id="groupIdSelect" lay-filter="select-groupId-filter">
                                <<option value="">请选择组别</option>
                                {{# layui.each(indexData.groupList, function(index, item){ }}
                                <option value="{{ item.id }}">{{item.groupName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="sourceId">
                                <option value="">请选择来源</option>
                                {{# layui.each(indexData.sourceList, function(index, item){ }}
                                <option value="{{ item.id }}">{{ item.userName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-test"></i>
                            </div>
                            <select name="customerClassId">
                                <option value="">请选择客户分类</option>
                                {{# layui.each(indexData.customerClassList, function(index, item){ }}
                                <option value="{{ item.id }}">{{ item.className }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>

                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-slider"></i>
                            </div>
                            <select name="customerGroupId">
                                <option value="">客户群组</option>
                                {{# layui.each(indexData.customerGroupList, function(index, item){ }}
                                <option value="{{ item.id }}">{{item.groupName }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>

                    <!--<div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                <div class="layui-input-inline">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-dollar"></i>
                    </div>
                    <select name="paymentCode">
                        <option value="">请选择支付方式</option>
                        {{# layui.each(indexData.paymentCode, function(index, item){ }}
                        <option value="{{ item.title }}">{{ item.description }}</option>
                        {{# }); }}
                    </select>
                </div>
            </div>-->
                </div>
            </div>

            <div class="layui-row">
                <div class="layui-col-md12">
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-list"></i>
                            </div>
                            <input type="text" name="number" placeholder="客户编号" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <input type="text" name="userName" placeholder="请输入名字" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-cols"></i>
                            </div>
                            <input type="text" name="mobile" placeholder="请输入客户电话" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline">
                            <div class="layui-input-prefix">
                                <i class="layui-icon"></i>
                            </div>
                            <select name="status">
                                <option value="">请选择时间模式</option>
                                {{# layui.each(indexData.timeList, function(index, item){ }}
                                <option value="{{ item.value }}">{{ item.description }}</option>
                                {{# }); }}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline layui-input-wrap layui-input-wrap-prefix">
                        <div class="layui-input-inline core-time-input ">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-time"></i>
                            </div>
                            <input type="text" name="createTime" id="searchTime-CoreCmsUser-createTime" placeholder="请选择时间" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsUser-search" id="LAY-app-CoreCmsUser-search"><i class="layui-icon layui-icon-search"></i>筛选</button>
                        <button class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="LAY-app-CoreCmsUser-clearSearch"><i class="layui-icon layui-icon-delete"></i>取消</button>

                    </div>



                    <div style="padding-top:20px;">
                        <button class="layui-btn layui-btn-sm" lay-submit lay-filter="doShowDiv" id="doShowDiv"><i class="layui-icon layui-icon-search"></i>转资料</button>
                        </div>
                        <div style="padding-top:20px;display:none"><button class="layui-btn layui-btn-sm" lay-submit lay-filter="selectData" id="selectData"><i class="layui-icon layui-icon-search"></i>选中数据</button></div>
                        <div id="showDiv" style="display: none;">
                            <div class="layui-form" lay-filter="customForm">
                                {{# layui.each(indexData.sysUserList, function(index, item){ }}
                                <input type="checkbox" name="option" value="{{item.id}}" title="{{item.nickName}}" lay-skin="primary" class="custom-radio">
                                {{# }); }}
                                <!--<input type="checkbox" name="option" value="1" title="选项 1" lay-skin="primary" class="custom-radio">
                <input type="checkbox" name="option" value="test" title="选项 2" lay-skin="primary" class="custom-radio">
                <input type="checkbox" name="option" value="3" title="选项 3" lay-skin="primary" class="custom-radio">-->
                            </div>
                            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="cancelSelect" id="cancelSelect"><i class="layui-icon layui-icon-clear"></i>取消</button>
                            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="cancelSelect1" id="cancelSelect1"><i class="layui-icon layui-icon-add-circle"></i>新单</button>
                            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="cancelSelect2" id="cancelSelect2"><i class="layui-icon layui-icon-add-circle"></i>淘单</button>
                            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="cancelSelect3" id="cancelSelect3"><i class="layui-icon layui-icon-add-circle"></i>复购</button>
                        </div>
                    </div>
                </div>
     

        </div>
    </form>
</script>

<script type="text/html" id="LAY-app-CoreCmsUser-pagebar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addData"><i class="layui-icon layui-icon-add-1"></i>添加数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="inputData"><i class="layui-icon layui-icon-add-1"></i>导入数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="selectExportExcel"><i class="layui-icon layui-icon-add-circle"></i>选择导出</button>
        <button class="layui-btn layui-btn-sm" lay-event="queryExportExcel"><i class="layui-icon layui-icon-download-circle"></i>查询导出</button>
    </div>
</script>

<script type="text/html" id="LAY-app-CoreCmsUser-tableBox-bar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="editBalance">修改余额</a>
    <a class="layui-btn layui-btn-xs" lay-event="editPoint">修改积分</a>
    <a class="layui-btn layui-btn-xs" lay-event="editParentId">修改推荐人</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="addFollowRecords">跟进</a>
    <a class="layui-btn layui-btn-xs" lay-event="addOrder">下单</a>
</script>

<script>
    var indexData;
    layui.data.done = function (d) {
        indexData = d.data;
        console.log(d.data);
        layui.use(['index', 'table', 'laydate', 'util', 'coreHelper'],
            function () {
                var $ = layui.$
                    , admin = layui.admin
                    , table = layui.table
                    , form = layui.form
                    , laydate = layui.laydate
                    , setter = layui.setter
                    , coreHelper = layui.coreHelper
                    , util = layui.util
                    , view = layui.view;


                var searchwhere;
                //监听搜索
                form.on('checkbox', function (data) {
                    console.log(data, 'data--->')

                    if (data.elem.className === 'custom-radio') {
                        console.log("当前选中：", data.value);

                        // 先清空所有选中项
                        document.querySelectorAll(".custom-radio").forEach(checkbox => {
                            checkbox.checked = false;
                        });

                        // 只保留当前点击的项
                        data.elem.checked = true;

                        // 重新渲染表单，使 UI 正确显示
                        setTimeout(() => {
                            form.render('checkbox');
                        }, 50);
                        return false
                    }
                   
                });
                form.on('select(select-companyId-filter)', function (data) {
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值
                    var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
          
                    layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象

                    coreHelper.Post("Api/SysUser/DepartmentList", { id: value }, function (e) {
                        console.log(e, "hhhhh");
             
                        $('#departmentSelect').empty();
                        $('#groupIdSelect').empty();

                        console.log(e.data, '---e.data---->')
                        if (e.data.length > 0 && !e.data[0].Error) {
                            var firstValue = 0;
                            $.each(e.data, function (h, z) {
                                $('#departmentSelect').append("<option value=" + z.id + ">" + z.depName + "</option>")
                                if (h == 0) {
                                    firstValue = z.id;
                                }

                                console.log("dfsfsdfsd", z.id);
                            });

                            if (firstValue) {
                                coreHelper.Post("Api/SysUser/GroupList", { id: firstValue }, function (ed) {
                                    console.log(ed);

                                    if (ed.data.length > 0) {
                                        $('#groupIdSelect').empty();
                                        // $('#groupIdSelect').value();
                                        $.each(ed.data, function (hd, zd) {
                                            $('#groupIdSelect').append("<option value=" + zd.id + ">" + zd.groupName + "</option>")
                                        });
                                        document.getElementById('groupIdSelect').value = '';
                                        document.getElementById('departmentSelect').value = '';
                                        form.render();
                                    }
                                });

                            }
                            console.log(firstValue);
                        }
                        form.render();

                    });
                });

                form.on('select(select-departmentId-filter)', function (data) {

                    console.log(data, 'data--->')
                    var elem = data.elem; // 获得 select 原始 DOM 对象
                    var value = data.value; // 获得被选中的值
                    var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
                    layer.msg(this.innerHTML + ' 的 value: ' + value); // this 为当前选中 <option> 元素对象

                    coreHelper.Post("Api/SysUser/GroupList", { id: value }, function (e) {
                        console.log(e);
                        $('#groupIdSelect').empty();
                        console.log(e.data, '----e-data---->')
                        if (e.data.length > 0) {
                            // $('#groupIdSelect').value();
                            $.each(e.data, function (h, z) {
                                $('#groupIdSelect').append("<option value=" + z.id + ">" + z.groupName + "</option>")
                            });
                        }
                        document.getElementById('groupIdSelect').value = '';
                        form.render();
                    });

                });

                form.on('submit(doShowDiv)',
                    function (data) {

                        var checkStatus = table.checkStatus('LAY-app-CoreCmsUser-tableBox')
                        var checkData = checkStatus.data;

                        if (checkData.length === 0) {
                            layer.msg('请选中客户');
                            return false
                        }
                        $('#showDiv').toggle();
                        return false; // 阻止默认 form 跳转
                    });
                    //转单
                form.on('submit(selectData)',
                    function (data) {

                        var selectedValues = [];
                       
                        // 获取所有选中的 checkbox
                        document.querySelectorAll('.custom-radio:checked').forEach(checkbox => {
                            selectedValues.push(checkbox.value); // 收集选中的值
                        });
                        // 打印或显示选中的值
                        var number = "hh";
                        console.log('选中的值：', selectedValues[0]);
                        if (selectedValues[0] == undefined) {
                            layer.msg("请选择销售");
                            return false;
                        }
                        var checkStatus = table.checkStatus('LAY-app-CoreCmsUser-tableBox')
                        var checkData = checkStatus.data;
                        layer.confirm('确认转吗？',
                            function (index) {
                                var delidsStr = [];
                                layui.each(checkData,
                                    function (index, item) {
                                        delidsStr.push(item.id);
                                    });
                                layer.close(index);
                                coreHelper.Post("Api/CoreCmsUser/ChangeUser", { id: delidsStr, sysid: selectedValues[0] }, function (e) {
                                    if (e.code === 0) {
                                        layer.msg("操作成功");
                                        window.open(e.data);
                                    } else {
                                        layer.msg(e.msg);
                                    }
                                });
                            });

                        return false; // 阻止默认 form 跳转
                    });
                form.on('submit(cancelSelect)',
                    function (data) {
                       document.querySelectorAll('.custom-radio').forEach(checkbox => {
                        checkbox.checked = false;  // 取消选中状态
                    });

                    // 重新渲染表单，更新 UI
                    setTimeout(() => {
                        form.render('checkbox');
                    }, 50);
                      //  $('#showDiv').toggle();
                        return false; // 阻止默认 form 跳转
                    });
                    //新单
                form.on('submit(cancelSelect1)',
                    function (data) {

                        var selectedValues = [];

                        // 获取所有选中的 checkbox
                        document.querySelectorAll('.custom-radio:checked').forEach(checkbox => {
                            selectedValues.push(checkbox.value); // 收集选中的值
                        });
                        // 打印或显示选中的值
                        var number = "hh";
                        console.log('选中的值：', selectedValues[0]);
                        if (selectedValues[0] == undefined) {
                            layer.msg("请选择销售");
                            return false;
                        }
                        var checkStatus = table.checkStatus('LAY-app-CoreCmsUser-tableBox')
                        var checkData = checkStatus.data;
                        if (checkData.length == 0) {
                            layer.msg("请选择客户");
                            return false;
                        }
                        console.log("h哈哈哈哈", checkData);
                        layer.confirm('确认转吗？',
                            function (index) {
                                var delidsStr = [];
                                layui.each(checkData,
                                    function (index, item) {
                                        delidsStr.push(item.id);
                                    });
                                layer.close(index);
                                coreHelper.Post("Api/CoreCmsUser/ChangeUser", { id: delidsStr, sysid: selectedValues[0] }, function (e) {
                                    if (e.code === 0) {
                                        layer.msg("操作成功");
                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                       /* window.open(e.data);*/
                                    } else {
                                        layer.msg(e.msg);
                                    }
                                });
                            });

                        return false; // 阻止默认 form 跳转
                    });

                    //淘单
                form.on('submit(cancelSelect2)',
                    function (data) {

                        var selectedValues = [];

                        // 获取所有选中的 checkbox
                        document.querySelectorAll('.custom-radio:checked').forEach(checkbox => {
                            selectedValues.push(checkbox.value); // 收集选中的值
                        });
                        // 打印或显示选中的值
                        var number = "hh";
                        console.log('选中的值：', selectedValues[0]);
                        if (selectedValues[0] == undefined) {
                            layer.msg("请选择销售");
                            return false;
                        }
                        var checkStatus = table.checkStatus('LAY-app-CoreCmsUser-tableBox')
                        var checkData = checkStatus.data;
                        if (checkData.length == 0) {
                            layer.msg("请选择客户");
                            return false;
                        }
                        console.log("h哈哈哈哈", checkData);
                        layer.confirm('确认转吗？',
                            function (index) {
                                var delidsStr = [];
                                layui.each(checkData,
                                    function (index, item) {
                                        delidsStr.push(item.id);
                                    });
                                layer.close(index);
                                coreHelper.Post("Api/CoreCmsUser/TaodanUser", { id: delidsStr, sysid: selectedValues[0] }, function (e) {
                                    if (e.code === 0) {
                                        layer.msg("操作成功");
                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                        /* window.open(e.data);*/
                                    } else {
                                        layer.msg(e.msg);
                                    }
                                });
                            });
                       // $('#showDiv').toggle();
                        return false; // 阻止默认 form 跳转
                    });
                form.on('submit(cancelSelect3)',
                    function (data) {

                        var selectedValues = [];

                        // 获取所有选中的 checkbox
                        document.querySelectorAll('.custom-radio:checked').forEach(checkbox => {
                            selectedValues.push(checkbox.value); // 收集选中的值
                        });
                        // 打印或显示选中的值
                        var number = "hh";
                        console.log('选中的值：', selectedValues[0]);
                        if (selectedValues[0] == undefined) {
                            layer.msg("请选择销售");
                            return false;
                        }
                        var checkStatus = table.checkStatus('LAY-app-CoreCmsUser-tableBox')
                        var checkData = checkStatus.data;
                        if (checkData.length == 0) {
                            layer.msg("请选择客户");
                            return false;
                        }
                        console.log("h哈哈哈哈", checkData);
                        layer.confirm('确认转吗？',
                            function (index) {
                                var delidsStr = [];
                                layui.each(checkData,
                                    function (index, item) {
                                        delidsStr.push(item.id);
                                    });
                                layer.close(index);
                                coreHelper.Post("Api/CoreCmsUser/RepurchaseUser", { id: delidsStr, sysid: selectedValues[0] }, function (e) {
                                    if (e.code === 0) {
                                        layer.msg("操作成功");
                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                        /* window.open(e.data);*/
                                    } else {
                                        layer.msg(e.msg);
                                    }
                                });
                            });
                        return false; // 阻止默认 form 跳转
                    });
                //监听搜索
                form.on('submit(LAY-app-CoreCmsUser-search)',
                    function (data) {
                        var field = data.field;
                        console.log("cecccc", field);
                        searchwhere = field;
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsUser-tableBox', { where: field, page: { curr: 1 } });
                        return false; // 阻止默认 form 跳转
                    });

                //监听清空
                form.on('submit(LAY-app-CoreCmsUser-clearSearch)',
                    function (data) {
                        $('#LAY-app-CoreCmsUser-toolbar-form')[0].reset();
                        //执行重载
                        table.reloadData('LAY-app-CoreCmsUser-tableBox', { where: "", page: { curr: 1 } });
                        return false; // 阻止默认 form 跳转
                    });
                //数据绑定
                table.render({
                    elem: '#LAY-app-CoreCmsUser-tableBox',
                    url: layui.setter.apiUrl + 'Api/CoreCmsUser/GetPageList',
                    method: 'POST',
                    toolbar: '#LAY-app-CoreCmsUser-toolbar',
                    pagebar: '#LAY-app-CoreCmsUser-pagebar',
                    className: 'pagebarbox',
                    defaultToolbar: ['filter', 'print', 'exports'],
                    height: 'full-132',//无面包屑127,搜索框189,1行62
                    page: true,
                    limit: 30,
                    limits: [10, 15, 20, 25, 30, 50, 100, 200],
                    text: { none: '暂无相关数据' },
                    cols: [
                        [
                            { type: "checkbox", fixed: "left" },
                            { field: 'id', title: '序列', sort: false, width: 70 },
                            { field: 'userName', title: '客户名称', sort: false, width: 100 },
                            { field: 'number', title: '客户编号', sort: false, width: 100 },
                            { field: 'mobile', title: '手机号', sort: false, width: 100 },
                            { field: 'amount', title: '累计金额', sort: false, width: 100 },
                            { field: 'orderNumber', title: '累计次数', sort: false, width: 100 },
                            {
                                field: 'orderTypeId', title: '订单类型', sort: false, width: 105, templet: function (data) {
                                    if (data.orderTypeId) {
                                        for (i = 0; i < d.data.orderTypeList.length; i++) {
                                            if (data.orderTypeId === d.data.orderTypeList[i].id) {
                                                return d.data.orderTypeList[i].orderName;
                                            }
                                        }
                                        return "";
                                    } else {
                                        return "";
                                    }
                                }
                            },
                            //{
                            //    field: 'sex', title: '性别', sort: false, width: 60, templet: function (data) {
                            //        console.log("111111", data.sex);
                            //        if (data.sex) {
                            //            for (i = 0; i < d.data.sexTypes.length; i++) {
                            //                if (data.sex === d.data.sexTypes[i].value) {
                            //                    return d.data.sexTypes[i].title;
                            //                }
                            //            }
                            //        } else {
                            //            return "";
                            //        }
                            //    }
                            //},
                            {
                                field: 'companyId', title: '归属公司', sort: false, width: 105, templet: function (data) {
                                    if (data.companyId) {
                                        for (i = 0; i < d.data.companyList1.length; i++) {
                                            if (data.companyId === d.data.companyList1[i].id) {
                                                return d.data.companyList1[i].companyName;
                                            }
                                        }
                                        return "";
                                    } else {
                                        return "";
                                    }
                                }
                            },
                            {
                                field: 'departmentId', title: '归属部门', sort: false, width: 105, templet: function (data) {
                                    console.log("测试测测试", d.data.sysUserList);
                                    if (data.sysid) {
                                        for (i = 0; i < d.data.departmentList1.length; i++) {
                                            if (data.departmentId === d.data.departmentList1[i].id) {
                                                return d.data.departmentList1[i].depName;
                                            }
                                        }
                                        return "";
                                    } else {
                                        return "";
                                    }
                                }
                            },
                            {
                                field: 'groupId', title: '归属组别', sort: false, width: 105, templet: function (data) {
                                    console.log("测试测测试", d.data.sysUserList);
                                    if (data.groupId) {
                                        for (i = 0; i < d.data.groupList1.length; i++) {
                                            if (data.groupId === d.data.groupList1[i].id) {
                                                return d.data.groupList1[i].groupName;
                                            }
                                        }
                                        return "";
                                    } else {
                                        return "";
                                    }
                                }
                            },
                            {
                                field: 'sysid', title: '归属销售', sort: false, width: 105, templet: function (data) {
                                    console.log("测试测测试", d.data.sysUserList);
                                    if (data.sysid) {
                                        for (i = 0; i < d.data.sysUserList.length; i++) {
                                            if (data.sysid === d.data.sysUserList[i].id) {
                                                return d.data.sysUserList[i].nickName;
                                            }
                                        }
                                        return "";
                                    } else {
                                        return "";
                                    }
                                }
                            },
                            { field: 'remarks', title: '备注', width: 130, sort: false },
                            { field: 'address', title: '地址', width: 130, sort: false },

                            { field: 'oneDivideTime', title: '新单分配时间', width: 130, sort: false },
                            { field: 'otherDivideTime', title: '其他分配时间', width: 130, sort: false },
                            { field: 'createTime', title: '创建时间', width: 130, sort: false },
                            { width: 282, align: 'center', title: '操作', fixed: 'right', toolbar: '#LAY-app-CoreCmsUser-tableBox-bar' }
                        ]
                    ]
                });
                //监听排序事件
                table.on('sort(LAY-app-CoreCmsUser-tableBox)', function (obj) {
                    table.reloadData('LAY-app-CoreCmsUser-tableBox', {
                        initSort: obj, //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                        where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                            orderField: obj.field, //排序字段
                            orderDirection: obj.type //排序方式
                        }
                    });
                });
                //头工具栏事件
                table.on('toolbar(LAY-app-CoreCmsUser-tableBox)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    console.log(obj.config.id, ' console.log(obj.config.id)--->')
                    switch (obj.event) {
                        case 'addData':
                            doCreate();
                            break;
                        case 'selectExportExcel':
                            doSelectExportExcel(checkStatus);
                            break;
                        case 'queryExportExcel':
                            doQueryExportexcel();
                            break;
                    };
                });
                //头工具栏事件
                table.on('pagebar(LAY-app-CoreCmsUser-tableBox)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'addData':
                            doCreate();
                            break;
                        case 'inputData':
                            doInputData();
                            break;
                        case 'selectExportExcel':
                            doSelectExportExcel(checkStatus);
                            break;
                        case 'queryExportExcel':
                            doQueryExportexcel();
                            break;
                    };
                });
                //执行创建操作
                function doInputData() {
                    admin.popup({
                        shadeClose: false,
                        title: '上传数据',
                        area: ['800px', '300px'],
                        id: 'LAY-popup-CoreCmsUser-create',
                        success: function (layero, index) {
                            view(this.id).render('user/userInfo/getUpLoadExcel', {}).done(function () {
                                //监听提交
                                form.on('submit(LAY-app-getUpLoad-submit)',
                                    function (data) {
                                        var field = data.field; //获取提交的字段
                                        console.log(field);

                                        //提交 Ajax 成功后，关闭当前弹层并重载表格
                                        coreHelper.Post("Api/CoreCmsUser/DoUploadUserInfos", field, function (e) {
                                            console.log(e)
                                            if (e.code === 0) {
                                                layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                layer.close(index); //再执行关闭
                                                layer.msg(e.msg);
                                            } else {
                                                layer.msg(e.msg);
                                            }
                                        });
                                    });
                            });
                        }
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            layero.contents().find("#LAY-app-getUpLoad-submit").click();
                        }
                    });
                }
                //监听工具条
                table.on('tool(LAY-app-CoreCmsUser-tableBox)',
                    function (obj) {
                        if (obj.event === 'edit') {
                            doEdit(obj)
                        } else if (obj.event === 'editBalance') {
                            doEditBalance(obj);
                        } else if (obj.event === 'editPoint') {
                            doEditPoint(obj)
                        } else if (obj.event === 'editParentId') {
                            doEditParentId(obj)
                        } else if (obj.event === 'addFollowRecords') {
                            doAddFollowRecords(obj)
                        } else if (obj.event === 'addOrder') {
                            doAddOrder(obj)
                        }
                    });
                //执行创建操作
                function doCreate() {
                    coreHelper.Post("Api/CoreCmsUser/GetCreate", null, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '创建数据',
                                area: ['800px', '800px'],
                                id: 'LAY-popup-CoreCmsUser-create',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/create', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsUser-createForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
                                                console.log("sfsdfdf", field);
                                                field.isDelete = field.isDelete == 'on';
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoCreate", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    });
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsUser-createForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行编辑操作
                function doEdit(obj) {
                    coreHelper.Post("Api/CoreCmsUser/GetEdit", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '编辑数据',
                                area: ['800px', '800px'],
                                id: 'LAY-popup-CoreCmsUser-edit',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/edit', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsUser-editForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                field.isDelete = field.isDelete == 'on';
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoEdit", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsUser-editForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }

                //执行编辑余额
                function doEditBalance(obj) {
                    coreHelper.Post("Api/CoreCmsUser/GetEditBalance", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '修改余额',
                                area: ['500px', '350px'],
                                id: 'LAY-popup-CoreCmsUser-EditBalance',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/editBalance', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsUser-editBalanceForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段
                                                field.data = parseFloat(field.data).toFixed(2);

                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoEditBalance", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsUser-editBalanceForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行跟进记录
                function doAddFollowRecords(obj) {
                    coreHelper.Post("Api/CoreCmsFollowRecords/GetCreate", { number: obj.data.number }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '跟进记录',
                                area: ['900px', '900px'],
                                id: 'LAY-app-CoreCmsFollowRecords-create',
                                success: function (layero, index) {
                                    view(this.id).render('followRecords/create', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsFollowRecords-createForm-submit)',
                                            function (data) {
                                               
                                                var field = data.field; //获取提交的字段
                                                field.number = obj.data.number;
                                                field.data = parseFloat(field.data).toFixed(2);
                                              
                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsFollowRecords/DoCreate", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsFollowRecords-tableBox'); //重载表格
                                                        //layer.close(index); //再执行关闭
                                                       
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                             
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行下单
                function doAddOrder(obj) {
                    coreHelper.Post("Api/CoreCmsOrder/AddGetByNumber", { number: obj.data.number }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '新增订单',
                                area: ['1020px', '1000px'],
                                id: 'LAY-app-CoreCmsUser-edit',
                                success: function (layero, index) {
                                    view(this.id).render('order/orders/AddOrderindex', { data: e.data }).done(function () {
                                        //监听提交
                                        console.log('--ddd-->')
                                        //LAY-app-CoreCmsUser-orderForm-submit这个是保存客户资料按钮ID
                                     
                                        form.on('submit(LAY-app-CoreCmsUser-orderForm-submit)',
                                            function (data) {
                                                console.log(data, '---3-data-213123----->')
                                          
                                                // 这个位置就可以提交数据了吧
                                            /*    if (data.elem.)*/

                                                var field = data.field; //获取提交的字段
                                                field.number = obj.data.number;
                                                field.data = parseFloat(field.data).toFixed(2);

                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoEdit", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        //layer.close(index); //再执行关闭

                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                       
                                        form.on('submit(LAY-app-CoreCmsUser-saveAddOrderForm-submit)',
                                            function (data) {
                                                console.log(data.field, '--1--data-213123----->')
                                              
                                                // 这个位置就可以提交数据了吧
                                                /*    if (data.elem.)*/

                                                var field = data.field; //获取提交的字段
                                                var khnumber = field.number;
                                                field.orderId = "";
                                                if (field.orderAmount=="") {

                                                    layer.msg("请输入订单总金额");
                                                    return false;
                                                }
                                                var pattern3 = new RegExp("[0-9]+");
                                                if (!pattern3.test(field.orderAmount)) {

                                                    alert('请输入数字');
                                                    return false;

                                                }
                                                if (field.paymentCode == "") {

                                                    layer.msg("请选择支付方式");
                                                    return false;
                                                }
                                                if (field.orderTypeName == "") {

                                                    layer.msg("请选择订单类型");
                                                    return false;
                                                }
                                                console.log(field, '--1--data-99999999----->')
                                                coreHelper.Post("Api/CoreCmsOrder/GetCartListBy", { number:khnumber }, function (e) {
                                                    console.log("sdfsddswwwww", field)
                                                    if (e.data.length > 0) {
                                                            coreHelper.Post("Api/CoreCmsOrder/SaveAddOrder", field, function (e) {
                                                               // console.log(e,"sfdsfsfsfsfsffsfsfdddddddddddd")
                                                                if (e.code === 0) {
                                                                    layui.table.reloadData('LAY-app-CoreCmsNewCart-tableBox'); //重载表格
                                                                    //layer.close(index); //再执行关闭LAY-app-CoreCmsOrderRecords-toolbar
                                                                   // layui.table.reloadData('LAY-app-CoreCmsNewCart-tableBox'); //重载表格

                                                                    layer.msg(e.msg);
                                                                } else {
                                                                    layer.msg(e.msg);
                                                                }
                                                            });
                                                       
                                                    }
                                                    else {
                                                        layer.msg("请选择产品");
                                                    }
                                                    //if (e.code === 0) {
                                                    //    layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                    //    //layer.close(index); //再执行关闭

                                                    //    layer.msg(e.msg);
                                                    //} else {
                                                    //    layer.msg(e.msg);
                                                    //}
                                                });
                                                //if (field.goodsId) {
                                                //    //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                //    coreHelper.Post("Api/CoreCmsOrder/SaveAddOrder", field, function (e) {
                                                //        console.log(e)
                                                //        if (e.code === 0) {
                                                //            layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                //            //layer.close(index); //再执行关闭

                                                //            layer.msg(e.msg);
                                                //        } else {
                                                //            layer.msg(e.msg);
                                                //        }
                                                //    });
                                                //} else {
                                                //    layer.msg("请选择产品");
                                                //}
                                            });
                                       
                                    })
                                }

                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                //执行编辑积分
                function doEditPoint(obj) {
                    coreHelper.Post("Api/CoreCmsUser/GetEditPoint", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '修改积分',
                                area: ['500px', '350px'],
                                id: 'LAY-popup-CoreCmsUser-EditPoint',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/editPoint', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsUser-editPointForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoEditPoint", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsUser-editPointForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }
                 
                //执行修改推荐人
                function doEditParentId(obj) {
                    coreHelper.Post("Api/CoreCmsUser/GetEditParentId", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '修改推荐人',
                                area: ['500px', '350px'],
                                id: 'LAY-popup-CoreCmsUser-EditParentId',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/editParentId', { data: e.data }).done(function () {
                                        //监听提交
                                        form.on('submit(LAY-app-CoreCmsUser-editParentIdForm-submit)',
                                            function (data) {
                                                var field = data.field; //获取提交的字段

                                                //提交 Ajax 成功后，关闭当前弹层并重载表格
                                                coreHelper.Post("Api/CoreCmsUser/DoEditParentId", field, function (e) {
                                                    console.log(e)
                                                    if (e.code === 0) {
                                                        layui.table.reloadData('LAY-app-CoreCmsUser-tableBox'); //重载表格
                                                        layer.close(index); //再执行关闭
                                                        layer.msg(e.msg);
                                                    } else {
                                                        layer.msg(e.msg);
                                                    }
                                                });
                                            });
                                    })
                                }
                                , btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    layero.contents().find("#LAY-app-CoreCmsUser-editParentIdForm-submit").click();
                                }
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }

                //执行预览操作
                function doDetails(obj) {
                    coreHelper.Post("Api/CoreCmsUser/GetDetails", { id: obj.data.id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '查看详情',
                                area: ['800px', '600px'],
                                id: 'LAY-popup-CoreCmsUser-details',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/details', { data: e.data }).done(function () {
                                        form.render();
                                    });
                                }
                                , btn: ['关闭窗口']
                                , btnAlign: 'c'
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                }

                //积分记录
                $(document).on('click', '.point', function () {
                    var id = $(this).attr('data-id');
                    var searchType = $(this).attr('data-type');
                    coreHelper.Post("Api/CoreCmsUser/GetDetailsPointLog", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '查看详情',
                                area: ['1000px', '90%'],
                                id: 'LAY-popup-CoreCmsUser-details',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/detailsPointLog', { data: e.data, id: id, searchType: searchType }).done(function () {
                                        form.render();
                                    });
                                }
                                , btn: ['关闭窗口']
                                , btnAlign: 'c'

                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                });

                //余额明细
                $(document).on('click', '.balance', function () {
                    var id = $(this).attr('data-id');
                    coreHelper.Post("Api/CoreCmsUser/GetDetailsBalanceLog", { id: id }, function (e) {
                        if (e.code === 0) {
                            admin.popup({
                                shadeClose: false,
                                title: '查看详情',
                                area: ['1000px', '90%'],
                                id: 'LAY-popup-CoreCmsUser-details',
                                success: function (layero, index) {
                                    view(this.id).render('user/userInfo/detailsBalanceLog', { data: e.data, id: id }).done(function () {
                                        form.render();
                                    });
                                }
                                , btn: ['关闭窗口']
                                , btnAlign: 'c'
                            });
                        } else {
                            layer.msg(e.msg);
                        }
                    });
                });

                //执行查询条件导出excel
                function doQueryExportexcel() {
                    layer.confirm('确定根据当前的查询条件导出数据吗？',
                        function (index) {
                            var field = searchwhere;
                            coreHelper.PostForm("Api/CoreCmsUser/QueryExportExcel", field, function (e) {
                                if (e.code === 0) {
                                    window.open(e.data);
                                } else {
                                    layer.msg(e.msg);
                                }
                            });
                        });
                }

                //执行选择目录导出数据
                function doSelectExportExcel(checkStatus) {
                    var checkData = checkStatus.data;
                    if (checkData.length === 0) {
                        return layer.msg('请选择您要导出的数据');
                    }
                    layer.confirm('确定导出选择的内容吗？',
                        function (index) {
                            var delidsStr = [];
                            layui.each(checkData,
                                function (index, item) {
                                    delidsStr.push(item.id);
                                });
                            layer.close(index);
                            coreHelper.Post("Api/CoreCmsUser/SelectExportExcel", { id: delidsStr }, function (e) {
                                if (e.code === 0) {
                                    window.open(e.data);
                                } else {
                                    layer.msg(e.msg);
                                }
                            });
                        });
                }
                //监听 表格复选框操作

                layui.form.on('switch(switch_isDelete)', function (obj) {
                    coreHelper.Post("Api/CoreCmsUser/DoSetisDelete", { id: this.value, data: obj.elem.checked }, function (res) {
                        layer.msg(res.msg);
                    });
                });

                laydate.render({
                    elem: '#searchTime-CoreCmsUser-createTime',
                    range: '到',
                    type: 'datetime'
                });
                laydate.render({
                    elem: '#searchTime-updataTime',
                    range: '到',
                    type: 'datetime'
                });
                //重载form
                form.render();

            });
    };
</script>

<!--设置删除标志 有数据就是删除-->
<script type="text/html" id="switch_isDelete">
    <input type="checkbox" name="switch_isDelete" value="{{d.id}}" lay-skin="switch" lay-text="已删除|正常" lay-filter="switch_isDelete" {{ d.isDelete ? 'checked' : '' }}>
</script>